$.ajax({
    type:"post",
    url:"/system/getPageModuleList",
    data:{},
    dataType:"json",
    success:function (r){
        if (r.data !=null){
            var t = "<tr>" +
                "<th>序号</th>" +
                "<th>模块名称</th>" +
                "<th>父模块</th>" +
                "<th>URL</th>" +
                "<th>状态</th>" +
                "<th>操作</th>" +
                "</tr>>";
            for (var i = 0; i < r.data.length; i++) {
                let moduleUrl = "#";
                if (r.data[i].module_murl==""||r.data[i].module_murl==null){
                    r.data[i].module_murl = moduleUrl;
                }
                let fatherId = r.data[i].module_pid;
                let fatherName = "无";
                if (r.data[i].module_fname==""||r.data[i].module_fname==null){
                    r.data[i].module_fname = fatherName;
                }
                var n = "";
                var m = "";
                var k = "";
                if ((r.data[i].module_state) == "0"){
                    n = "正常";
                    m = "禁用";
                    k = "是否确禁用此模块？";
                }else {
                    n = "禁用";
                    m = "启动";
                    k = "是否确启用此模块？";
                }
                t += "<tr><td>"+r.data[i].module_id+"</td>" +
                    "<td>"+r.data[i].module_rname+"</td>" +
                    "<td>"+r.data[i].module_fname+"</td>" +
                    "<td>"+r.data[i].module_murl+"</td>" +
                    "<td>"+n+"</td>" +
                    "<td> <a href='javascript:void(0);' class='tablelink'>修改</a>" +
                    "<a href='javascript:void(0);' class='tablelink' onclick=\"tipOpen('"+k+"')\">"+m+"</a>" +
                    "</td></tr>";
            }
            $(".tablelist").html(t);
            var pagenum = document.getElementById("pagenum");
            pagenum.innerHTML = r.pageNum;
            var totalrows = document.getElementById("totalrows");
            totalrows.innerHTML = r.totalRows;

            $(".tablelink").click(function(){

                var text = $(this).text();
                var module_id = $(this).parents("tr")[0].children[0].innerHTML
                if (text == "修改") {
                    window.location.href = "/system/updateModuleView/" + module_id;
                }else if(text=="禁用"){
                    $("#sure").click(function () {
                        $.ajax({
                            type: "post",
                            url: "/system/updateModulePositionByState/"+ module_id+"/"+1,
                            data: {},
                            dataType: "json",
                            success: function (r) {
                                if (r=="true"){
                                    alert("禁用成功");
                                }else{
                                    alert("禁用失败");
                                }
                            }
                        })
                    })
                }else if(text=="启用"){
                    $("#sure").click(function () {
                        $.ajax({
                            type: "post",
                            url: "/system/updateModulePositionByState/"+ module_id+"/"+0,
                            data: {},
                            dataType: "json",
                            success: function (r) {
                                if (r=="true"){
                                    alert("启用成功");
                                }else{
                                    alert("启用失败");
                                }
                            }
                        })
                    })
                }
            });

            $("#shangyiye").click(function (){
                if (pagenum.innerHTML>1){
                    pagenum.innerHTML = Number(pagenum.innerHTML)-1;
                }else {
                    alert("已经是第一页了")
                }

                var n = pagenum.innerHTML;
                if (n>=1){
                    $.ajax({
                        type:"post",
                        url:"/system/getPageModuleList",
                        data:{pageNum:n},
                        dataType:"json",
                        success:function (r) {
                            if (r.data != null) {
                                var t = "<tr>" +
                                    "<th>序号</th>" +
                                    "<th>模块名称</th>" +
                                    "<th>父模块</th>" +
                                    "<th>URL</th>" +
                                    "<th>状态</th>" +
                                    "<th>操作</th>" +
                                    "</tr>>";
                                for (var i = 0; i < r.data.length; i++) {
                                    var url = "#";
                                    if (r.data[i].module_murl == ""||r.data[i].module_murl==null) {
                                        r.data[i].module_murl = url;
                                    }
                                    let fatherId = r.data[i].module_pid;
                                    let fatherName = "无";
                                    if (r.data[i].module_fname==""||r.data[i].module_fname==null){
                                        r.data[i].module_fname = fatherName;
                                    }
                                    var n = "";
                                    var m = "";
                                    var k = "";
                                    if ((r.data[i].module_state) == "0"){
                                        n = "正常";
                                        m = "禁用";
                                        k = "是否确禁用此模块？";
                                    } else {
                                        n = "禁用";
                                        m = "启动";
                                        k = "是否确启用此模块？";
                                    }
                                    t += "<tr><td>" + r.data[i].module_id + "</td>" +
                                        "<td>" + r.data[i].module_rname + "</td>" +
                                        "<td>" + r.data[i].module_fname + "</td>" +
                                        "<td>" + r.data[i].module_murl + "</td>" +
                                        "<td>" + n + "</td>" +
                                        "<td> <a href='javascript:void(0);' class='tablelink'>修改</a>" +
                                        "<a href='javascript:void(0);' class='tablelink' onclick=\"tipOpen('"+k+"')\">" + m + "</a>" +
                                        "</td></tr>";
                                }
                                $(".tablelist").html(t);
                                var pagenum = document.getElementById("pagenum");
                                pagenum.innerHTML = r.pageNum;
                                var totalrows = document.getElementById("totalrows");
                                totalrows.innerHTML = r.totalRows;

                                $(".tablelink").click(function () {

                                    var text = $(this).text();
                                    var module_id = $(this).parents("tr")[0].children[0].innerHTML
                                    if (text == "修改") {
                                        window.location.href = "/system/updateModuleView/" + module_id;
                                    } else if (text == "禁用") {
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateModulePositionByState/" + module_id + "/" + 1,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                    if (r == "true") {
                                                        alert("禁用成功");
                                                    } else {
                                                        alert("禁用失败");
                                                    }
                                                }
                                            })
                                        })
                                    } else if (text == "启用") {
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateModulePositionByState/" + module_id + "/" + 0,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                    if (r == "true") {
                                                        alert("启用成功");
                                                    } else {
                                                        alert("启用失败");
                                                    }
                                                }
                                            })
                                        })
                                    }
                                });
                            }
                        },
                    })
                }else {
                    alert("已经是第一页了");
                }
            })

            $("#xiayiye").click(function (){
                if (pagenum.innerHTML<r.totalPage){
                    pagenum.innerHTML = Number(pagenum.innerHTML)+1;
                }else {
                    alert("已经是最后一页了")
                }

                var n = pagenum.innerHTML;
                if (n<=r.totalPage){
                    $.ajax({
                        type:"post",
                        url:"/system/getPageModuleList",
                        data:{pageNum:n},
                        dataType:"json",
                        success:function (r) {
                            if (r.data != null) {
                                var t = "<tr>" +
                                    "<th>序号</th>" +
                                    "<th>模块名称</th>" +
                                    "<th>父模块</th>" +
                                    "<th>URL</th>" +
                                    "<th>状态</th>" +
                                    "<th>操作</th>" +
                                    "</tr>>";
                                for (var i = 0; i < r.data.length; i++) {
                                    var url = "#";
                                    if (r.data[i].module_murl == ""||r.data[i].module_murl==null) {
                                        r.data[i].module_murl = url;
                                    }
                                    let fatherId = r.data[i].module_pid;
                                    let fatherName = "无";
                                    if (r.data[i].module_fname==""||r.data[i].module_fname==null){
                                        r.data[i].module_fname = fatherName;
                                    }
                                    var n = "";
                                    var m = "";
                                    var k = "";
                                    if ((r.data[i].module_state) == "0"){
                                        n = "正常";
                                        m = "禁用";
                                        k = "是否确禁用此模块？";
                                    } else {
                                        n = "禁用";
                                        m = "启动";
                                        k = "是否确启用此模块？";
                                    }
                                    t += "<tr><td>" + r.data[i].module_id + "</td>" +
                                        "<td>" + r.data[i].module_rname + "</td>" +
                                        "<td>" + r.data[i].module_fname + "</td>" +
                                        "<td>" + r.data[i].module_murl + "</td>" +
                                        "<td>" + n + "</td>" +
                                        "<td> <a href='javascript:void(0);' class='tablelink'>修改</a>" +
                                        "<a href='javascript:void(0);' class='tablelink' onclick=\"tipOpen('"+k+"')\">" + m + "</a>" +
                                        "</td></tr>";
                                }
                                $(".tablelist").html(t);
                                var pagenum = document.getElementById("pagenum");
                                pagenum.innerHTML = r.pageNum;
                                var totalrows = document.getElementById("totalrows");
                                totalrows.innerHTML = r.totalRows;

                                $(".tablelink").click(function () {

                                    var text = $(this).text();
                                    var module_id = $(this).parents("tr")[0].children[0].innerHTML
                                    if (text == "修改") {
                                        window.location.href = "/system/updateModuleView/" + module_id;
                                    } else if (text == "禁用") {
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateModulePositionByState/" + module_id + "/" + 1,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                    if (r == "true") {
                                                        alert("禁用成功");
                                                    } else {
                                                        alert("禁用失败");
                                                    }
                                                }
                                            })
                                        })
                                    } else if (text == "启用") {
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateModulePositionByState/" + module_id + "/" + 0,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                    if (r == "true") {
                                                        alert("启用成功");
                                                    } else {
                                                        alert("启用失败");
                                                    }
                                                }
                                            })
                                        })
                                    }
                                });
                            }
                        },
                    })
                }else {
                    alert("已经是最后一页了");
                }
            })
        }
    }
})

$("#check").click(function (){
    var module_rname = $("#moduleName").val();

    $.ajax({
        type:"post",
        url: "/system/queryOneModule",
        data:{module_rname:module_rname},
        dataType:"json",
        success:function (r) {
            if (r.data != null) {
                var t = "<tr>" +
                    "<th>序号</th>" +
                    "<th>模块名称</th>" +
                    "<th>父模块</th>" +
                    "<th>URL</th>" +
                    "<th>状态</th>" +
                    "<th>操作</th>" +
                    "</tr>>";
                for (var i = 0; i < r.data.length; i++) {
                    var url = "#";
                    if (r.data[i].module_murl == ""||r.data[i].module_murl==null) {
                        r.data[i].module_murl = url;
                    }
                    let fatherId = r.data[i].module_pid;
                    let fatherName = "无";
                    if (r.data[i].module_fname==""||r.data[i].module_fname==null){
                        r.data[i].module_fname = fatherName;
                    }
                    var n = "";
                    var m = "";
                    var k = "";
                    if ((r.data[i].module_state) == "0"){
                        n = "正常";
                        m = "禁用";
                        k = "是否确禁用此模块？";
                    } else {
                        n = "禁用";
                        m = "正常";
                        k = "是否确启用此模块？";
                    }
                    t += "<tr><td>" + r.data[i].module_id + "</td>" +
                        "<td>" + r.data[i].module_rname + "</td>" +
                        "<td>" + r.data[i].module_fname + "</td>" +
                        "<td>" + r.data[i].module_murl + "</td>" +
                        "<td>" + n + "</td>" +
                        "<td> <a href='javascript:void(0);' class='tablelink'>修改</a>" +
                        "<a href='javascript:void(0);' class='tablelink' onclick=\"tipOpen('"+k+"')\">" + m + "</a>" +
                        "</td></tr>";
                }
                $(".tablelist").html(t);
                var pagenum = document.getElementById("pagenum");
                pagenum.innerHTML = r.pageNum;
                var totalrows = document.getElementById("totalrows");
                totalrows.innerHTML = r.totalRows;

                $(".tablelink").click(function () {

                    var text = $(this).text();
                    var module_id = $(this).parents("tr")[0].children[0].innerHTML
                    if (text == "修改") {
                        window.location.href = "/system/updateModuleView/" + module_id;
                    } else if (text == "禁用") {
                        $("#sure").click(function () {
                            $.ajax({
                                type: "post",
                                url: "/system/updateModulePositionByState/" + module_id + "/" + 1,
                                data: {},
                                dataType: "json",
                                success: function (r) {
                                    if (r == "true") {
                                        alert("禁用成功");
                                    } else {
                                        alert("禁用失败");
                                    }
                                }
                            })
                        })
                    } else if (text == "启用") {
                        $("#sure").click(function () {
                            $.ajax({
                                type: "post",
                                url: "/system/updateModulePositionByState/" + module_id + "/" + 0,
                                data: {},
                                dataType: "json",
                                success: function (r) {
                                    if (r == "true") {
                                        alert("启用成功");
                                    } else {
                                        alert("启用失败");
                                    }
                                }
                            })
                        })
                    }
                });
            }
        },
    })

})
